﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace CartoonViewer
{
    public static class ControlExtention
    {
        public delegate void InvokeHandler();

        public static void SafeInvoke(this Control control, InvokeHandler handler)
        {

            control.Dispatcher.Invoke(handler, System.Windows.Threading.DispatcherPriority.Normal);
            //if (control.InvokeRequired)
            //{
            //    control.Invoke(handler);
            //}
            //else
            //{
            //    handler();
            //}
        }

        public static void SafeInvoke(this Control control, InvokeHandler handler, object[] args)
        {
            control.Dispatcher.Invoke(handler, System.Windows.Threading.DispatcherPriority.Normal, args);
            //if (control.InvokeRequired)
            //{
            //    control.Invoke(handler, args);
            //}
            //else
            //{
            //    handler();
            //}
        }
    }
}
